package com.ruoyi.web.controller;

import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.business.Complain;
import com.ruoyi.business.qo.ComplainQO;
import com.ruoyi.business.service.ComplainService;
import com.ruoyi.common.common.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @title: ComplainController
 * @copyright: copyright (c) 2021
 * @author: jiangguanjun
 * @date: 2023/10/5 10:33
 * @firstReview:
 * @lastReview:
 * @desc: 投诉相关
 */
@Api(value = "ComplainController", tags = "投诉相关 ")
@RestController
@Slf4j
@RequestMapping("/complain")
public class ComplainController {
    @Autowired
    private ComplainService complainService;



    @CrossOrigin
    @GetMapping("/list")
    @ApiOperation(value = "投诉列表  页面：客服-会员投诉")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "title", value = "标题", dataType = "String"),
            @ApiImplicitParam(name = "createStartTime", value = "注册开始时间", dataType = "String"),
            @ApiImplicitParam(name = "createEndTime", value = "注册结束时间", dataType = "String"),
            @ApiImplicitParam(name = "deal", value = "是否已经处理 0：未处理，1：已处理", dataType = "Integer"),
    })
    public ResultBody<IPage<Complain>> list(@RequestParam(value = "title" ,required = false) String title,
                                            @RequestParam(value = "createStartTime" ,required = false) String createStartTime,
                                            @RequestParam(value = "createEndTime" ,required = false) String createEndTime,
                                            @RequestParam(value = "deal" ,required = false) Integer deal){


        ComplainQO complainQO = new ComplainQO() ;
        complainQO.setTitle(title);
        complainQO.setDeal(deal);
        log.info("complainQO:::::::{}",complainQO);
        if(createEndTime != null){
            complainQO.setCreateEndDate(createEndTime + " 23:59:59");
        }
        if(createStartTime != null){
            complainQO.setCreateStartDate(createStartTime+" 00:00:00");
        }
        return complainService.queryByPage(complainQO) ;
    }


    @CrossOrigin
    @PostMapping("/deal")
    @ApiOperation(value = "处理投诉  页面：客服-会员投诉")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deal", value = "是否已经处理 0：未处理，1：已处理", dataType = "Integer"),
            @ApiImplicitParam(name = "id", value = "id", dataType = "Integer")
    })
    public ResultBody deal(@RequestBody JSONObject jsonObject){


        Integer deal = jsonObject.getInteger("deal") ;
        Integer id = jsonObject.getInteger("id") ;

        Integer res = complainService.deal(deal,id) ;
        return ResultBody.success(res>0) ;
    }


}

